package com.gitee.wsl.common.chart.sample.arc.model


import com.gitee.wsl.api.SelectAbleItem
import com.gitee.wsl.math.Math
import com.gitee.wsl.jvm.math.round
import timber.log.Timber

/**
 * @ClassName ArcLineData
 * @Description  弧线比较图数据类
 * @author XiongChuanLiang<br/>(xcl_168@aliyun.com)
 *
 */

class ArcLineData(
    var key: String = "",
    var label: String = "",
    var value: Float = 0.0f,
    var color: Int = 0
):SelectAbleItem {

    override var isSelected: Boolean = false

    /**
     * 返回当前百分比
     * @return 百分比
     */
    fun getPercentage(): Float {
        return value
    }

    /**
     * 将百分比转换为图显示角度
     * @return 圆心角度
     */
    val sliceAngle: Float
       get() {
        var angle = 0.0f
        try {
            val currentValue: Float = this.getPercentage()
            if (currentValue >= 101f || currentValue < 0.0f) {
                Timber.d( "输入的百分比不合规范.须在0~100之间.")
            } else {
                //Angle = (float) Math.rint( 360f *  (currentValue / 100f) );
                angle = Math.round(360f * (currentValue / 100f), 2)
            }
        } catch (ex: Exception) {
            angle = -1f
        }
        return angle
    }
}